home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / luff stuff / luff⁄adm.c next >
Encoding:
C/C++ Source or Header  |  1985-11-08  |  2.3 KB  |  111 lines  |  [TEXT/MACA]

  1. #include "MacLuff.h"
  2.  
  3. /* The main program which administrate who's on the move etc */
  4.  
  5. main(){
  6.     int x, y;
  7.     struct QDVar QDVar;
  8.     DateTimeRec date_record;
  9.  
  10.     QD = &QDVar;
  11.  
  12.     /* Standard initialisation */
  13.     InitGraf(&thePort);
  14.     InitFonts();
  15. /*  FlushEvents(everyEvent, 0);                 */
  16.     InitWindows();
  17.     InitMenus();
  18. /*  TEInit();                                   */
  19.     InitDialogs((ProcPtr) 0);
  20.     InitCursor();
  21.  
  22.     /* Application dependent initialisation */
  23.     init_the_w();
  24.     SetPort(the_w);
  25.     init_the_menu();
  26.     h_curs = GetCursor(FINGER); finger = **h_curs;
  27.  
  28.     for(x = 0; x < XZIZE; x++)
  29.        for(y = 0; y < YZIZE; y++)
  30.         board[x][y] = ' ';
  31.     done_flag = message_flag = FALSE;
  32.  
  33.     GetTime(&date_record);
  34.     srand(date_record.second);
  35.  
  36.     while(TRUE){
  37.     while(TRUE){
  38.         if(Button())
  39.         slf = FALSE;
  40.         if(!slf)
  41.         inmove(&x, &y); /* This is the main event loop */
  42.         if(slf){
  43.         if(playcnt){
  44.             if(!chose('x', &x, &y)){
  45.             draw_message("Can't find a place for my 'x'");
  46.             break;
  47.             }
  48.         }
  49.         else{
  50.             x = XZIZE/2;
  51.             y = YZIZE/2;
  52.         }
  53.         }
  54.         play[x][y] = ++playcnt;
  55.         draw_x(x, y);
  56.         board[x][y] = 'x';
  57.         if(update(x, y)){
  58.         draw_message("Congratulations you won");
  59.         break;
  60.         }
  61.         if(!chose('o', &x, &y)){
  62.         draw_message("Can't find a place for my 'o'");
  63.         break;
  64.         }
  65.         play[x][y] = ++playcnt;
  66.         draw_o(x, y);
  67.         board[x][y] = 'o';
  68.         if(update(x, y)){
  69.         draw_message("I won");
  70.         break;
  71.         }
  72.     }
  73.     DisableItem(my_menus[3], SHOW_GAME);
  74.     DisableItem(my_menus[3], HINT);
  75.     done_flag = TRUE;
  76.     slf = FALSE;
  77.     }
  78. }
  79.  
  80. init_the_w(){
  81.     int x, y;
  82.  
  83.     the_w = GetNewWindow(WINDOW, &w_record, (WindowPtr) -1);
  84.  
  85.     SetRect(&play_r, 0, 35, XZIZE*15, YZIZE*15 + 35);
  86.     SetRect(&message_r, 0, 0, 450, 34);
  87.     for(x = 0; x < XZIZE; x++)
  88.     for(y = 0; y < YZIZE; y++)
  89.         SetRect(&xy_r[x][y], x*15 - 1, y*15 + 34, x*15 + 15, y*15 + 50);
  90.     SetRect(&hole_r[0], 130, 15, 140, 25);
  91.     SetRect(&hole_r[1], 160, 15, 170, 25);
  92.     SetRect(&hole_r[2], 270, 15, 280, 25);
  93.     SetRect(&hole_r[3], 300, 15, 310, 25);
  94. }
  95.  
  96. init_the_menu(){
  97.     my_menus[0] = GetMenu(APPLE);
  98.     InsertMenu(my_menus[0], 0);
  99.  
  100.     my_menus[1] = GetMenu(FILE);
  101.     InsertMenu(my_menus[1], 0);
  102.  
  103.     my_menus[2] = GetMenu(HELP);
  104.     InsertMenu(my_menus[2], 0);
  105.  
  106.     my_menus[3] = GetMenu(COMMAND);
  107.     InsertMenu(my_menus[3], 0);
  108.  
  109.     DrawMenuBar();
  110. }
  111.